package com.lsj.fileutil.Type;

import com.google.gson.Gson;
import com.lsj.fileutil.FileUtil;
import com.lsj.pojo.Type;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;

import javax.servlet.http.HttpSession;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Component
public class TypeUtil {
    @Value("${typefileurl}")
    private String typeFileUrl;
    @Autowired
    FileUtil util;
    public List<Map<String,String>> getAll() throws Exception {
        List<String>strList = util.read(typeFileUrl);
        List<Map<String,String>> list =new ArrayList<Map<String, String>>();
        Gson gs=new Gson();
        for(String str:strList){
            Type type= gs.fromJson(str,Type.class);
            System.out.println( type.getTypeurl()+"  "+type.getTypename());
            Map<String,String> map =new HashMap<String, String>();
            map.put("id",type.getTypeurl());
            map.put("text",type.getTypename());
            list.add(map);
        }
        return list;
    }

}
